package ModelLayer;

import java.util.ArrayList;
import DBLayer.MapName;
import java.io.InvalidObjectException;

/**
 *
 * @author Moulde
 */
public class Actor
{
    @MapName(ColumnName="Name")
    private String name;
    @MapName(ColumnName="Address")
    private String address;
    @MapName(ColumnName="Phonenumber")
    private String phonenumber;
    @MapName(ColumnName="Country")
    private String country;
    @MapName(ColumnName="ZipCode")
    private String zipCode;
    @MapName(ColumnName="City")
    private String city;
    @MapName(ColumnName="Email")
    private String email;
    @MapName(ColumnName="ID")
    private int actorID;

    private ArrayList<Role> roles;

    public Actor(String name, String address, String phonenumber, String country, String zipCode, String city, String email)
    {
        this.name = name;
        this.address = address;
        this.phonenumber = phonenumber;
        this.country = country;
        this.zipCode = zipCode;
        this.city = city;
        this.email = email;

        roles = new ArrayList<Role>();
    }

    public Actor()
    {
        roles = new ArrayList<Role>();
    }

    public Actor clone()
    {
        Actor actor = new Actor();
        actor.setActorID(actorID);
        actor.setAddress(address);
        actor.setCity(city);
        actor.setCountry(country);
        actor.setEmail(email);
        actor.setName(name);
        actor.setPhonenumber(phonenumber);
        actor.setZipCode(zipCode);

        return actor;
    }

    public ArrayList<Role> getRoles()
    {
        return roles;
    }

    public void addRole(Role role)
    {
        if (role != null)
        {
            roles.add(role);
        }
    }
    
    public boolean isRolePresent(String rolename)
    {
        for (Role currentRole : roles)
        {
            if (currentRole.getRole().toLowerCase().equals(rolename.toLowerCase()))
            {
                return true;
            }
        }
        return false;
    }

    public Role getRole(String rolename) throws InvalidObjectException
    {
        for (Role currentRole : roles)
        {
            if (currentRole.getRole().toLowerCase().equals(rolename.toLowerCase()))
            {
                return currentRole;
            }
        }
        throw new InvalidObjectException(rolename + " could not be found on this actor");
    }

    public int getActorID()
    {
        return actorID;
    }

    public void setActorID(int actorID)
    {
        this.actorID = actorID;
    }

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    public String getCity()
    {
        return city;
    }
    
    public void setCity(String city)
    {
        this.city = city;
    }

    public String getCountry()
    {
        return country;
    }

    public void setCountry(String country)
    {
        this.country = country;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getPhonenumber()
    {
        return phonenumber;
    }

    public void setPhonenumber(String phonenumber)
    {
        this.phonenumber = phonenumber;
    }

    public String getZipCode()
    {
        return zipCode;
    }

    public void setZipCode(String zipCode)
    {
        this.zipCode = zipCode;
    }

    @Override
    public String toString()
    {
        return this.getName() + " - " + this.getPhonenumber();
    }


}
